package com.limingfeiyu.platform.management.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.limingfeiyu.common.utils.ChineseCharacterUtil;
import com.limingfeiyu.common.web.PageTable;
import com.limingfeiyu.platform.management.entity.HospitalInformation;
import com.limingfeiyu.platform.management.entity.LoginUser;
import com.limingfeiyu.platform.management.mapper.HospitalInformationMapper;
import com.limingfeiyu.platform.management.service.IHospitalInformationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 医院信息 服务实现类
 * </p>
 *
 * @author 黎铭飞羽
 * @since 2024-04-08
 */
@Service
public class HospitalInformationServiceImpl extends ServiceImpl<HospitalInformationMapper, HospitalInformation> implements IHospitalInformationService {

    @Override
    public Page<HospitalInformation> pageList(PageTable<HospitalInformation> pageTable) {
        QueryWrapper<HospitalInformation> userQw = new QueryWrapper<>();
        if (pageTable.getParam() != null) {
            userQw.lambda()
                    // 医院名称
                    .like(StringUtils.hasText(pageTable.getParam().getHospitalName()),
                            HospitalInformation::getHospitalName,
                            pageTable.getParam().getHospitalName())
                    .orderByAsc(HospitalInformation::getCreateTime);
        }
        Page<HospitalInformation> page = super.page(pageTable.getPage(), userQw);
        return page;
    }

    @Override
    public HospitalInformation findOneHospitalName(String hospitalName) {
        LambdaQueryWrapper<HospitalInformation> hilqw = new LambdaQueryWrapper<>();
        hilqw.eq(HospitalInformation::getHospitalName, hospitalName)
                .orderByAsc(HospitalInformation::getCreateTime);
        List<HospitalInformation> list = super.list(hilqw);
        if (list == null || list.size() <= 0) {
            return null;
        }
        return list.get(0);
    }


}
